#!/usr/bin/env python3
"""
PLOOP数据解析调试器
"""

import re

def debug_parse():
    """调试解析过程"""
    
    # 读取文件
    with open('717.txt', 'r', encoding='utf-8') as f:
        content = f.read()
    
    lines = content.split('\n')
    print(f"总行数: {len(lines)}")
    
    # 找到所有FRMWORK
    frmwork_lines = []
    ploop_lines = []
    pavert_lines = []
    frad_lines = []
    
    for i, line in enumerate(lines):
        line = line.strip()
        if line.startswith('NEW FRMWORK'):
            frmwork_lines.append((i+1, line))
        elif line == 'NEW PLOOP':
            ploop_lines.append(i+1)
        elif line == 'NEW PAVERT':
            pavert_lines.append(i+1)
        elif line.startswith('FRAD'):
            frad_lines.append((i+1, line))
    
    print(f"\n发现的结构:")
    print(f"FRMWORK数量: {len(frmwork_lines)}")
    print(f"PLOOP数量: {len(ploop_lines)}")
    print(f"PAVERT数量: {len(pavert_lines)}")
    print(f"FRAD数量: {len(frad_lines)}")
    
    print(f"\n前5个FRMWORK:")
    for i, (line_num, line) in enumerate(frmwork_lines[:5]):
        print(f"  行{line_num}: {line}")
    
    print(f"\n前5个PLOOP行号: {ploop_lines[:5]}")
    
    print(f"\n所有FRAD行:")
    for line_num, line in frad_lines:
        print(f"  行{line_num}: {line}")
    
    # 分析第一个PLOOP的结构
    if ploop_lines:
        first_ploop_line = ploop_lines[0]
        print(f"\n分析第一个PLOOP (行{first_ploop_line}):")
        
        # 找到对应的FRMWORK
        frmwork_name = "未找到"
        for line_num, line in frmwork_lines:
            if line_num < first_ploop_line:
                frmwork_name = line.split()[2] if len(line.split()) > 2 else "Unknown"
        
        print(f"  对应FRMWORK: {frmwork_name}")
        
        # 显示PLOOP周围的行
        start = max(0, first_ploop_line - 10)
        end = min(len(lines), first_ploop_line + 50)
        
        print(f"  PLOOP周围内容 (行{start+1}-{end}):")
        for i in range(start, end):
            marker = ">>> " if i == first_ploop_line - 1 else "    "
            print(f"  {marker}{i+1:3d}: {lines[i].strip()}")

if __name__ == "__main__":
    debug_parse() 